- Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSolution.py
32 lines (25 loc) · 960 Bytes
/
Solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
fromqueueimportSimpleQueue
classSolution:
defwatchedVideosByFriends(self, watchedVideos: List[List[str]], friends: List[List[int]], id: int, level: int) ->List[str]:
levels= [100] *len(friends)
levels[id] =0
queue=SimpleQueue()
queue.put((id, 0))
count= {}
ret= []
whilenotqueue.empty():
i, k=queue.get()
ifk>level:
break
forfriendinfriends[i]:
iflevels[friend] >k+1:
levels[friend] =k+1
queue.put((friend, k+1))
foriinrange(len(friends)):
iflevels[i] ==level:
forvideoinwatchedVideos[i]:
ifvideonotincount:
count[video] =0
ret.append(video)
count[video] +=1
returnsorted(ret, key=lambdav: (count[v], v))